<template>
  <h1>表格组件</h1>
  <el-table :data="arr" style="width: 600px;margin: 0 auto">
    <el-table-column label="编号" type="index" width="80" align="center"></el-table-column>
    <el-table-column label="姓名" prop="name"></el-table-column>
    <el-table-column label="工资" prop="salary"></el-table-column>
    <el-table-column label="岗位" prop="job"></el-table-column>
    <el-table-column label="操作"  align="center">
      <template #default="scope">
        <el-button type="danger" @click="del(scope.$index,scope.row)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script setup>
import {ref} from "vue";
import index from "vuex";
//定义数组用来模拟从后端请求回来的对象数组
const arr = ref([
  {name:'RR一',salary:'1000',job:'饲养员'},
  {name:'RR二',salary:'2000',job:'饲养员'},
  {name:'RR三',salary:'3000',job:'饲养员'},
  {name:'RR四',salary:'4000',job:'饲养员'},
  {name:'RR五',salary:'5000',job:'饲养员'},
  {name:'RR六',salary:'6000',job:'饲养员'},
  {name:'RR七',salary:'7000',job:'饲养员'}
]);
const del =(index,row)=>{
  if (confirm('您确定要删除'+row.name+'吗')){
    arr.value.splice(index,1);
  }
}
</script>

<style scoped>

</style>